<template>
  <div>
    <div class="banner">
      <div class="imgs">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in banners" :key="index">
            <img :src="item.pic" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <div class="remLists">
      <div class="title">推荐</div>
      <div class="content">
        <ul class="clearfix">
          <li
            v-for="(item, index) in personalized"
            :key="index"
            @click="goMusiclist(item.id)"
          >
            <img :src="item.picUrl" alt="" />
            <span class="remd_lnum">{{ item.playCount | playCountA }}</span>
            <p>{{ item.name }}</p>
          </li>
        </ul>
      </div>
    </div>
    <dl class="musiclist">
      <dt>最新音乐</dt>
      <dd v-for="(item, index) in playlist.tracks" :key="index" @click="playmusic(item.id,item.name,item)">
        <div class="info">
          <img :src="item.picUrl" alt="">
          <div class="box1">
                      <h2>{{ item.name }}</h2>
          <h3>
            <span>{{ item.song.artists[0].name }}--{{ item.name }} &nbsp;&nbsp;</span>
          </h3>
          </div>
        </div>
      </dd>
    </dl>

  </div>
</template>


<script>
import { getBanner, getNewMusic, getPersonalized } from "../api/recommend";
export default {
  data() {
    return {
      banners: "",
      personalized: "",
      flag:true,
      value:'',
      coverImgUrl:'',
      ar:[],
      playlist:{
        tracks: []
      }
    };
  },
  methods: {
    getBannerFun() {
      // 请求数据
      getBanner().then((data) => {
        if (data.code == 200) {
          this.banners = data.banners;
        }
        console.log(data);
      });
    },
    getPersonalizedFun() {
      // 请求数据
      getPersonalized({ limit: 9 }).then((data) => {
        console.log(data);

        this.personalized = data.result;
      });
    },
    getNewsongs() {
      // 请求数据
      getNewMusic({ limit: 10 }).then((data) => {
        this.playlist.tracks = data.result
      });
    },
      playmusic(id, name, item) {
        console.log(item.song,"songsong")
      // console.log(item.picUrl )
      // console.log(id);
      // console.log(name);
      let playMusicData = {
        coverImgUrl: item.picUrl,
        id,
        name,
        ar: item.song.artists,
        tracks:this.playlist.tracks
      };
      // 数据存存储
      this.$store.commit("musicDatafun", playMusicData);
    },
    goMusiclist(id) {
      this.$router.push({
        path: "/recommend/musiclist",
        query: { id },
      });
    },
  },
  created() {
    this.getBannerFun();
    this.getPersonalizedFun();
    this.getNewsongs();
  },
  filters: {
    playCountA(value) {
      let w = value > 10000 ? value / 10000 : value; // 万计算
      let y = w > 10000 ? parseInt(w / 10000) + "亿" : parseInt(w) + "万"; //亿计算
      return y;
    },
  },
};
</script>


<style lang="less" scoped>
.banner {
  height: 228px;
  background-color: #0379db;
  width: 100%;
  position: relative;
  // margin-bottom: 55px;
  .imgs {
    min-height: 228px;
    position: absolute;
    left: 0px;
    right: 0px;
    top: 0px;
    margin: auto;
    width: 96%;
    background-color: #0379db;
    border-radius: 5px;
    img {
      width: 100%;
    }
  }
}
.remLists {
  margin-bottom: 24px;
  .title {
    font-size: 0.34375rem;
    height: 100px;
    line-height: 100px;
    font-weight: bold;
    text-indent: 0.5em;
  }
  .content li {
    width: 33.33%;
    float: left;
    position: relative;
    margin-bottom: 16px;
    img {
      display: block;
      width: 3.125rem;
      height: 3.125rem;
      margin: 0 auto;
      border-radius: 3px;
    }
    p {
      font-size: 0.28125rem;
      color: #2f3035;
      height: 0.78125rem;
      overflow: hidden;
      line-height: 0.4375rem;
      padding: 0.15625rem 0.109375rem;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .remd_lnum {
      position: absolute;
      top: 0px;
      right: 20px;
      font-size: 0.234375rem;
      color: #fff;
    }
  }
}
.musiclist {
  border-radius: 12px;
  background-color: #fff;
  position: relative;
  top: -12px;
  min-height: 200px;
  dt {
    padding-left: 9px;
    margin-bottom: 14px;
    font-size: 17px;
    height: 20px;
    line-height: 20px;
    color: #333333;
    span {
      font-size: 23px;
      color: #616262;
    }
  }
  dd {
    height: 55px;
    border-bottom: 1px solid #e2e2e2;
    padding: 12px 0 0 12px;
    .info {
      img{
        width: 40px;
        height: 40px;
        float: left;
        border-radius: 3px;
      }
      .box1{
        float: left;
              h2 {
        height: 25px;
        font-size: 17px;
        color: #3a3c3c;
        font-weight: normal;
        padding-left: 10px;
      }
      h3 {
        height: 18px;
        font-size: 12px;
        color: #777978;
        font-weight: normal;
        padding-left: 10px;
      }
      }
    }
  }
}
</style>